<?php
/**
 * Nuclide Static Loader Extension
 * 
 * @package Nuclide
 * @author	Mats Lundberg 
 * @version $Id$
 */

/**
 * Uses regular inclusion instead of Nuclide::loadClass('util', 'nuc_Loader', 1); because this
 * code is used by the Nuclide class.
 */
include_once( dirname(__FILE__) . '/nuc_loader.class.php' );

/**
 * Load classes from files according to certain rules. Useful for lazy inclusion of php files.
 * 
 * Note that every new inherited static loader actually uses the same nuc_Loader object. Since php static inheritance
 * behaves a bit unexpected. Can cause problem in rare circumstances.
 * 
 * Usage:
 * <code>
 * class MyLoader extends nuc_StaticLoader {}
 * 
 * MyLoader::instance()->setRootDirectory('/path/to/desired/root/');
 * 
 * MyLoader::loadClass('foo');
 * </code>
 *
 * @package	Nuclide
 * @author	Mats Lundberg
 * @todo 	Advanced ruleset. Perhaps make it like the Zend_View includer.
 * @todo	Two versions who have much in common. Abstract it some more.
 */
abstract class nuc_StaticLoader implements nuc_Loader_Static_Interface
{
	/**
	 * The singleton instance.
	 *
	 * @staticvar nuc_Loader
	 */
	protected static $instance;
	
	/**
	 * Return the singleton instance
	 *
	 * @return	Loader
	 */
	public static function instance() {
		if( is_null( self::$instance ) ) {
			self::$instance = new nuc_Loader( false );
		}
		
		return self::$instance;
	}
	
  	/**
	 * Load php-file with class.
	 *
	 * @param	string		Class name
	 */
	public static function loadClass( $className ) {
		self::instance()->loadClass( $className );
	}
	
  	/**
	 * Load php-file with functions.
	 *
	 * @param	string		Function name
	 * @static
	 */
	public static function loadFunctions( $functionsName ) {
		self::instance()->loadFunctions( $functionsName );
	}
		
	/**
	 * Find out if class is loadable, ie. exists where it should according to the rules.
	 *
	 * @param	string	Class name
	 * @return	bool
	 * @static
	 */
	public static function classLoadable( $className ) {
		return self::instance()->classLoadable( $className );
	}
	
	/**
	 * Set root directory. Actually we add a root directory to our singleton instance. Could cause unexpected clashes.
	 * Beacuse of the PHP defines static methods and member variables, this is how it must (?) be done.
	 *
	 * @param	string		Directory
	 * @static
	 */
	public static function setRootDirectory( $directory ) {
		self::instance()->addRootDirectory( $directory );
	}
}
?>